package Zoo.handler;


import Zoo.entity.AnimalEntity;
import Zoo.impl.ZoomenService1Impl;
import Zoo.service.ZoomenService1;
import Zoo.view.zoomanview.UpdateAnimalView;
import Zoo.view.zoomanview.ZoomenView1;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 动物饲养员修改动物信息界面处理类
 */
public class UpdateAnimalViewHandler implements ActionListener {
    private UpdateAnimalView updateAnimalView;
    private ZoomenView1 zoomenView1;


    public UpdateAnimalViewHandler(UpdateAnimalView updateAnimalView, ZoomenView1 zoomenView1) {
        this.updateAnimalView = updateAnimalView;
        this.zoomenView1 = zoomenView1;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JButton jButton = (JButton) e.getSource();
        String text = jButton.getText();
        if ("修改".equals(text)) {
            ZoomenService1 zoomenService1 = new ZoomenService1Impl();
            AnimalEntity animalEntity = updateAnimalView.buildUpdatedZooparkEntity();
            boolean updateResult = zoomenService1.update(animalEntity);
            if (updateResult) {
                //重新加载表格查到最新数据
                zoomenView1.reloadTable();
                updateAnimalView.dispose();
            } else {
                JOptionPane.showMessageDialog(updateAnimalView, "修改失败");

            }

        }
    }

}
